import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import Layout from '../layout/Layout.vue'

export const adminRoutes: RouteRecordRaw = {
  path: '/',
  redirect: '/index',
  component: Layout,
  children: [
    {
      path: '/index',
      name: 'master',
      meta: { title: '首页', icon: 'House', affix: true },
      component: () => import('../views/admin/Home.vue')
    },
    {
      path: '/ability',
      name: 'ability',
      meta: { title: '能力上报', icon: 'Edit' },
      component: () => import('../views/ability/index.vue')
    },
    {
      path: '/accesspull',
      name: 'access-pull',
      meta: { title: '拉取管理', icon: 'Link' },
      component: () => import('../views/pull-mgt/pull.vue')
    },
    {
      path: '/accessoff',
      name: 'access_off',
      meta: { title: '下架管理', icon: 'Download' },
      component: () => import('../views/off/index.vue')
    },
    {
      path: '/jfgl',
      name: 'jfgl',
      meta: { title: '交付管理', icon: 'Suitcase' },
      component: () => import('../views/jfgl/index.vue')
    }
  ]
}

const routes: RouteRecordRaw[] = [adminRoutes]

const router = createRouter({
  history: createWebHistory(`${import.meta.env.VITE_BASE}/main`),
  routes: [...routes]
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title || import.meta.env.VITE_SYS_NAME
  next()
})
export default router
